#!/usr/local/python/bin/python
# coding=utf-8
__author__ = 'cz'

import logging
import os.path

import tdtools.Config_tdsql_prd as config

_logger=logging.getLogger("data")

def initLog(_logFile, _logPrefix):
    global  _logger
    # 日志级别映射表
    LOG_LEVELS = {
        1: logging.ERROR,
        2: logging.WARNING,
        3: logging.INFO,
        4: logging.DEBUG
    }

    # 根据配置获取实际的日志级别
    actual_log_level = LOG_LEVELS.get(config.CURR_LOGLEVEL, logging.DEBUG)

    log_dir = config.LOG_DIR
    if not os.path.exists(log_dir) :
        os.makedirs(log_dir)
    path= (log_dir + '/' + _logFile)
    print("日志路径：%s"%path)
    file_handler = logging.FileHandler(path)
    formatter = logging.Formatter('[' + _logPrefix + '] %(asctime)s - %(levelname)s - %(message)s')
    file_handler.setFormatter(formatter)
    _logger.addHandler(file_handler)

    stream_handler=logging.StreamHandler()
    fmt = logging.Formatter('[' + _logPrefix + '] %(asctime)s - %(levelname)s - %(message)s')
    stream_handler.setFormatter(fmt)
    _logger.addHandler(stream_handler)

    _logger.setLevel(actual_log_level)





